/**
 * @(#)com.basic.demo.controller.ExceptionController
 *
 * Copyright (c) 2014-2018 一抹风光
 *
 * DESC:
 *
 */
package com.basic.demo.controller;

/**
 * @author fusf
 * @version 1.0  2017/3/12
 */

import com.basic.demo.exception.BusinessException;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseStatus;

@Controller
public class ErrorController {



    @ExceptionHandler(BusinessException.class)
   // @ResponseStatus(HttpStatus.NOT_FOUND)
    public void spittleNotFound() {
        System.out.println("异常处理中");
        //long spittleId = e.getSpittleId();
        // return new Error(4, "Spittle [" + spittleId + "] not found");
       // return null;
    }

    @RequestMapping(value = "/exception/index" ,method = RequestMethod.GET)
    public String printWelcome(ModelMap model) {
        model.addAttribute("message", "Hello world!");
        int i =0;
        if(i==0) {
            throw new BusinessException();
        }
        return "hello";
    }

          /**
         * 异常页面控制
         *
         * @param runtimeException
         * @return
         */
        @ExceptionHandler(RuntimeException.class)
        public String runtimeExceptionHandler(RuntimeException runtimeException,
                ModelMap modelMap) {
            //logger.error(runtimeException.getLocalizedMessage());

            modelMap.put("status", "500");
            return "exception";
        }

}
